package com.syphernova.learning.amst3;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

public class InputxJSON extends ActionBarActivity {
	public static final String EXTRA_XVALUE = "com.syphernova.learning.asmt3.xvalue";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_inputx_json);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.inputx_json, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	public void opendisplayxthjson(View view){
		Intent intent = null;

		EditText input = (EditText) findViewById(R.id.inputxjsonsocket);
		int xvalue = Integer.parseInt(input.getText().toString().trim());
		
		// get the current value of the 
		Intent sourceIntent = getIntent();
		
		String actionOnXVal = sourceIntent.getStringExtra(MainActivity.EXTRA_OPENWITHINTENT);
		
		if(actionOnXVal.equals("OpenSocket")){
			intent = new Intent(this, DisplayXthJSONLine.class);
			intent.putExtra(EXTRA_XVALUE, xvalue);
		}else if(actionOnXVal.equals("OpenHTTP")){
			intent = new Intent(this, DisplayXthJSONhttp.class);
			intent.putExtra(EXTRA_XVALUE, xvalue);
		}else{
			intent = new Intent(this, DisplayXthJSONCoord.class);
			intent.putExtra(EXTRA_XVALUE, xvalue);
		}
		startActivity(intent);
	}
}
